「超特急: 一時間でわかるML超入門」メモ
#min-caml #MinCaml
https://esumii.github.io/min-caml/index2.html
code:ocaml
# 1 + 2;;
- : int = 3
# 3 - 4;;
- : int = -1
# 5 * -6 ;;
- : int = -30
浮動小数点数の引き算は -.
文字列の連結は ^
code:ocaml
# 1.2 -. 3.4 ;;
- : float = -2.2
# "hello" ^ "world" ;;
- : string = "helloworld"
float_of_int で整数を浮動小数点数に変換
code:ocaml
# float_of_int 123 ;;
- : float = 123.
print_int で標準出力に整数を出力。返り値は () ユニットと呼ばれる値を返す
code:ocaml
# print_int 123 ;;
123- : unit = ()
print_newline は引数を持たない。引数を持たない関数を呼び出す時は引数にユニット () を与える。ユニットを与えないと関数自体が返るみたい。
code:ocaml
# print_newline () ;;
- : unit = ()
# print_newline ;;
- : unit -> unit = <fun>
標準ライブラリ
Randomははじめからロードされている。
code:ocaml
# Random.init 12345 ;;
- : unit = ()
# Random.int 10 ;;
- : int = 4
# Random.int 10 ;;
- : int = 6
# Random.int 10 ;;
- : int = 0
Sysモジュール
code:ocaml
# Sys.getcwd () ;;
- : string = "/Users/thata/src/misc"
最初からロードされているモジュール一覧
http://ocaml.jp/archive/ocaml-manual-3.06-ja/manual034.html
最初からロードされていないライブラリ
Unixモジュール
Strモジュール
Graphicsモジュール
Strモジュール
code:ocaml
# #load "str.cma" ;;
# Str.global_replace (Str.regexp "d...") "@@@@" "abcdefghijkl" ;;
- : string = "abc@@@@hijkl"
ライブラリはこちらを参照
http://ocaml.jp/archive/ocaml-manual-3.06-ja/